<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/common/init.ini"%>
<script language="javascript" src="plug_in/jQuery/jquerycomm.js"></script>
<script language="javascript" src="plug_in/jQuery/jqueryform.js"></script>
<html:hidden styleId="parameter_pages_currentPage" property="parameter.pages.currentPage" />
<html:hidden styleId="parameter_pages_maxPage" property="parameter.pages.maxPage"/>
<html:hidden styleId="parameter_pages_totalCount" property="parameter.pages.totalCount"/>
<html:hidden styleId="parameter_pages_pageSize" property="parameter.pages.pageSize"  />

<SCRIPT language=javascript>
var pageSize = 0;

/*
document.onreadystatechange = subSomething;//当页面加载状态改变的时候执行这个方法. 
function subSomething() 
{
if(document.readyState == "complete"){ //当页面加载状态为完全结束时进入  
 alert('dsfas');
 }
} 
*/
//首页
function submitFirstPage() {
	
    checkSeleced();//下一页丢失问题
	var page = parseInt(jQuery("#parameter_pages_currentPage").val()); 
	if (page == 1 || page == 0) {
		return;
	}
	jQuery("#parameter_pages_currentPage").val('1');
    Refreshpage();
}

/**
 * @Description：异步提交form
 * @param fnName 提交到action中的方法名
 * @param isResetCurrentPage 判断是查询还是刷新 0:刷新,1:查询
 * @author Rain
 * Mar 18, 2011
 */
 
function pagesRefresh(fnName,isResetCurrentPage){
	/*if (isResetCurrentPage==1){
	alert(isResetCurrentPage);
		document.all["parameter.pages.currentPage"].value=1;
	}*/
	jQuery("#formNameforPages").ajaxSubmit({
		async:false,
		success:function (data){              
			//重写分页插件
			var member = eval("("+data+")");	//包数据解析为json 格式
			jQuery("#maxPage").html(member[0].MaxPage);
			jQuery("#totalCount").html(member[0].TotalCount);
			jQuery("#currentPage").html(member[0].CurrentPage);
			jQuery("#parameter_pages_totalCount").val(member[0].TotalCount);
			jQuery("#parameter_pages_currentPage").val(member[0].CurrentPage);
			jQuery("#parameter_pages_maxPage").val(member[0].MaxPage);
			if(member[1].length==0 && jQuery("#parameter_pages_currentPage").val() !='1'){
				jQuery("#parameter_pages_currentPage").val(parseInt(jQuery("#parameter_pages_currentPage").val()) -1);
				pagesRefresh(fnName,isResetCurrentPage);
			}else{
				//调用当前页面中显示数据列表的方法
				showData(member[1]);
			}	
		},
		url:document.forms[0].action+'?theAction='+fnName
	});
}

//上一页
function submitPrePage() {
    checkSeleced();//下一页丢失问题
	var page = parseInt(jQuery("#parameter_pages_currentPage").val());
	
	if (page == 1 || page==0) {
		return;
	} 
	else {
		jQuery("#parameter_pages_currentPage").val(page-1);
	}
	Refreshpage();
}
function checkSeleced(){
	try{
		var select=getNowSelected();
		if(select!=""){
		   //jQuery("#hiddenselected").val() = select;
		}
	}catch(e){}

}
//下一页
function submitNextPage() {
    checkSeleced();//下一页丢失问题
	var page = parseInt(jQuery("#parameter_pages_currentPage").val());
	var mpage = parseInt(jQuery("#parameter_pages_.maxPage").val());
	
	if (page == mpage || mpage < page) {
		return;
	}else {
		jQuery("#parameter_pages_currentPage").val( page + 1);
	}
	Refreshpage();
}


//末页
function submitLastPage() {
	checkSeleced();//下一页丢失问题
	var page =  parseInt(jQuery("#parameter_pages_currentPage").val());
	var mpage = parseInt(jQuery("#parameter_pages_maxPage").val());
	if (page == mpage || mpage < page) {
		return;
	} 
	else {
		jQuery("#parameter_pages_currentPage").val(mpage);
	}
	Refreshpage();
}


//每页大小
function setPagesize(value){

	jQuery("#parameter_pages_currentPage").val(1);
	jQuery("#parameter_pages_pageSize").val(value);
	Refreshpage();
}

//跳转第n页
function setPagejump(value){
	
	if (parseInt(value) > parseInt(jQuery("#parameter_pages_maxPage").val()) ){
		alert("无法跳转");
	}else{
		jQuery("#parameter_pages_currentPage").val(value);
		Refreshpage();
	}
	
}
/*
function submitNoPage(value) {
	var page = parseInt($("pageno").value);
	var psize = $("parameter.pages.pageSize").value;
	var mpage = parseInt($("parameter.pages.maxPage").value);	
	var currentPage=parseInt($("parameter.pages.currentPage").value);
	if(isNaN(page) && $("pageno").value != ""){
		$("pageno").focus();
		$("pageno").value = "";
		return;
	}
	if(isNaN(psize) || psize < 1){
		$("parameter.pages.pageSize").focus();
		$("parameter.pages.pageSize").value = "";
		return;
	}
	if(value == "pageno"){
		if(isNaN(page) || page < 1){
			$("pageno").focus();
			$("pageno").value = "";
			return;
		}
		if (page > mpage) {
			$("pageno").focus();
			$("pageno").value = "";
			return;
		} 
		else if(page==currentPage){
			return;
		}else{
			$("parameter.pages.currentPage").value =page;
		}
	 }else{
		$("parameter.pages.currentPage").value = 1;
	}
	document.forms[0].submit();
}

function submitPage(page) 
{
	var mpage = parseInt($("parameter.pages.maxPage").value);
	var currentPage=parseInt($("parameter.pages.currentPage").value);
	if (page > mpage) {
		return;
	} 
	else if(page==currentPage){
		return;
	}else{
		$("parameter.pages.currentPage").value =page;
	}
	document.forms[0].submit();
}

function checkEmpty(){
	var psize = parseInt($("parameter.pages.pageSize").value);
	if(isNaN(psize) || psize < 1){
		$("parameter.pages.pageSize").value = pageSize;
	}
}
*/
</SCRIPT>

<div class="pagination">
	<div class="pageleft">
		<p class="pagenum">
			第
			<span id="currentPage" class="red"></span>页 / 共
			<span id="maxPage" class="red"></span>页， 跳转到
			<input type="text"
				onkeydown="if(event.keyCode==13) {return setPagejump(this.value)}"
				size=2 name=pageno />
			页 ，共
			<span id="totalCount" class="red"></span>条记录/ 每页显示
			<input type="text"
				onkeydown="if(event.keyCode==13) {return setPagesize(this.value)}"
				size="2" />
			条
		</p>
	</div>

	<div class="pageright">
		<!-- 分页位置 -->
		<div id="pagediv" class="paging">
			<span id="pagelist" class="pagelist"></span>
			<a id="first" href="javascript:void(0);"  onclick='submitFirstPage();'  class="first"
				title="首页">首 页</a>
			<a id="pre" href="javascript:submitPrePage() " class="prev"
				title="上一页">上一页</a>
			<a id="next" href="javascript:submitNextPage()" class="next"
				title="下一页">下一页</a>
			<a id="last" href="javascript:submitLastPage()" class="last"
				title="末页">末 页</a>
			<!-- 	 -->
		</div>
	</div>

</div>

